// pages/order_detail/order_detail.js
const app = getApp()
const Host = require('../../config').Host
Page({

    /**
     * 页面的初始数据
     */
    data: {
        coupon: {
            title: '优惠券11',
            value: 20,
        },
        intergration:{
            value:50,
            deduction:80,
        },
        submission: {},
        textValue: "",
        textValueLength: 24,
        all_price: '0.00',
        freight_method: '普通快递免运费',
        freight: '0.00',
        total_price: '00.00',
        sellerPhone:'',
    },
    promptAddress:function(){
        wx.showToast({
            title: '不可更改地址',
            icon:'none',
        })
    },
    promptCoupon: function () {
        wx.showToast({
            title: '不可更改优惠券',
            icon: 'none',
        })
    },
    promptIntergration:function(){
        wx.showToast({
            title: '不可更改积分使用',
            icon: 'none',
        })
    },
  call: function () {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.sellerPhone,
    })
  },
  //去付款
  payorder: function (e) {
    var that = this;
    var out_trade_no = e.currentTarget.id;//订单号
    var openid = wx.getStorageSync('openid');

    wx.request({
      url: Host + 'Pay/order_zhifu',
      data: { out_trade_no, openid },
      method: 'get',
      success: function (res) {
        if (res.data.code == 400) {
          wx.showToast({
            title: res.data.errmsg,
            icon: 'none',//  loading/success/none        
            duration: 2000
          })
        } else {
          wx.requestPayment({
            'appId': res.data.appId,
            'timeStamp': res.data.timeStamp,
            'nonceStr': res.data.nonceStr,
            'package': res.data.package,
            'signType': res.data.signType,
            'paySign': res.data.paySign,
            'success': function (res) {
              //console.log(res);
              wx.redirectTo({
                url: '/pages/submission_should_get/submission_should_get?id=2'
              })
            },
            'fail': function (res) {
              //console.log(res);
            }
          })
        }
      }
    })
  },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function (options) {
      var that = this;
      that.setData({
        orderid: options.id
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      var that = this;
      var orderid = that.data.orderid;

      wx.request({
        url: Host + 'Mine/orderDetail',
        data: { orderid },
        success: function (res) {
          //console.log(res.data);
          if (res.data.code == 200) {
            that.setData({
              submission: res.data.submission,
              all_price: res.data.submission.all_price,
              freight: res.data.submission.freight,
              total_price: res.data.submission.total_price,
              textValue: res.data.submission.textValue,
              sellerPhone: res.data.submission.telephone,
            })
          }
        }
      })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})